
/*
 * Copyright 2002-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 *版权所有2002-2018原作者。
 *
 *根据Apache许可证2.0版（“许可证”）许可；
 *除非符合许可证的规定，否则您不得使用此文件。
 *您可以在以下网址获取许可证副本
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 *除非适用法律要求或书面同意，否则软件
 *根据许可证分发是在“按原样”的基础上分发的，
 *无任何明示或暗示的保证或条件。
 *有关管理权限的特定语言，请参阅许可证
 *许可证下的限制。
 */

package org.springframework.context.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Profiles;

/**
 * Indicates that a component is eligible for registration when one or more
 * {@linkplain #value specified profiles} are active.
 *
 * <p>A <em>profile</em> is a named logical grouping that may be activated
 * programmatically via {@link ConfigurableEnvironment#setActiveProfiles} or declaratively
 * by setting the {@link AbstractEnvironment#ACTIVE_PROFILES_PROPERTY_NAME
 * spring.profiles.active} property as a JVM system property, as an
 * environment variable, or as a Servlet context parameter in {@code web.xml}
 * for web applications. Profiles may also be activated declaratively in
 * integration tests via the {@code @ActiveProfiles} annotation.
 *
 * <p>The {@code @Profile} annotation may be used in any of the following ways:
 * <ul>
 * <li>as a type-level annotation on any class directly or indirectly annotated with
 * {@code @Component}, including {@link Configuration @Configuration} classes</li>
 * <li>as a meta-annotation, for the purpose of composing custom stereotype annotations</li>
 * <li>as a method-level annotation on any {@link Bean @Bean} method</li>
 * </ul>
 *
 * <p>If a {@code @Configuration} class is marked with {@code @Profile}, all of the
 * {@code @Bean} methods and {@link Import @Import} annotations associated with that class
 * will be bypassed unless one or more of the specified profiles are active. A profile
 * string may contain a simple profile name (for example {@code "p1"}) or a profile
 * expression. A profile expression allows for more complicated profile logic to be
 * expressed, for example {@code "p1 & p2"}. See {@link Profiles#of(String...)} for more
 * details about supported formats.
 *
 * <p>This is analogous to the behavior in Spring XML: if the {@code profile} attribute of
 * the {@code beans} element is supplied e.g., {@code <beans profile="p1,p2">}, the
 * {@code beans} element will not be parsed unless at least profile 'p1' or 'p2' has been
 * activated. Likewise, if a {@code @Component} or {@code @Configuration} class is marked
 * with {@code @Profile({"p1", "p2"})}, that class will not be registered or processed unless
 * at least profile 'p1' or 'p2' has been activated.
 *
 * <p>If a given profile is prefixed with the NOT operator ({@code !}), the annotated
 * component will be registered if the profile is <em>not</em> active &mdash; for example,
 * given {@code @Profile({"p1", "!p2"})}, registration will occur if profile 'p1' is active
 * or if profile 'p2' is <em>not</em> active.
 *
 * <p>If the {@code @Profile} annotation is omitted, registration will occur regardless
 * of which (if any) profiles are active.
 *
 * <p><b>NOTE:</b> With {@code @Profile} on {@code @Bean} methods, a special scenario may
 * apply: In the case of overloaded {@code @Bean} methods of the same Java method name
 * (analogous to constructor overloading), an {@code @Profile} condition needs to be
 * consistently declared on all overloaded methods. If the conditions are inconsistent,
 * only the condition on the first declaration among the overloaded methods will matter.
 * {@code @Profile} can therefore not be used to select an overloaded method with a
 * particular argument signature over another; resolution between all factory methods
 * for the same bean follows Spring's constructor resolution algorithm at creation time.
 * <b>Use distinct Java method names pointing to the same {@link Bean#name bean name}
 * if you'd like to define alternative beans with different profile conditions</b>;
 * see {@code ProfileDatabaseConfig} in {@link Configuration @Configuration}'s javadoc.
 *
 * <p>When defining Spring beans via XML, the {@code "profile"} attribute of the
 * {@code <beans>} element may be used. See the documentation in the
 * {@code spring-beans} XSD (version 3.1 or greater) for details.
 *
 * @author Chris Beams
 * @author Phillip Webb
 * @author Sam Brannen
 * @since 3.1
 * @see ConfigurableEnvironment#setActiveProfiles
 * @see ConfigurableEnvironment#setDefaultProfiles
 * @see AbstractEnvironment#ACTIVE_PROFILES_PROPERTY_NAME
 * @see AbstractEnvironment#DEFAULT_PROFILES_PROPERTY_NAME
 * @see Conditional
 * @see org.springframework.test.context.ActiveProfiles
 */
/**
 *指示当一个或多个组件
 *｛@linkplain#值指定的配置文件｝处于活动状态。
 *
 *<p><em>配置文件</em>是一个可以激活的命名逻辑分组
 *通过｛@link ConfigurationEnvironment#setActiveProfiles｝以编程方式或声明方式
 *通过设置｛@link AbstractEnvironment#ACTIVE_PROFILES_PROPERTY_NAME
 *spring.profiles.active}属性作为JVM系统属性，作为
 *环境变量，或作为｛@code-web.xml｝中的Servlet上下文参数
 *用于web应用程序。配置文件也可以在中以声明方式激活
 *通过{@code@ActiveProfiles}注释进行集成测试。
 *
 *<p>｛@code@Profile｝注释可以以以下任何方式使用：
 *＜ul＞
 *<li>作为任何类上的类型级注释，直接或间接注释为
 *｛@code@Component｝，包括｛@link Configuration@Configuration｝类</li>
 *＜li＞作为元注释，用于编写自定义的构造型注释</li>
 *<li>作为任何{@link-Bean@Bean}方法的方法级注释</li>
 *</ul>
 *
 *<p>如果｛@code@Configuration｝类用｛@code@Profile｝标记，则所有
 *｛@code@Bean｝方法和与该类关联的｛@link Import@Import｝注释
 *将被绕过，除非一个或多个指定的配置文件处于活动状态。个人资料
 *字符串可以包含一个简单的配置文件名称（例如{@code“p1”}）或配置文件
 *表达。配置文件表达式允许更复杂的配置文件逻辑
 *例如{@code“p1&p2”}。有关详细信息，请参阅（字符串…）的｛@link Profiles#｝
 *有关支持格式的详细信息。
 *
 *＜p＞这类似于Spring XML中的行为：如果
 *提供了{@code-beans}元素，例如，{@code<beans profile=“p1，p2”>}
 *｛@code-beans｝元素将不会被解析，除非至少已经解析了配置文件“p1”或“p2”
 *激活。同样，如果标记了｛@code@Component｝或｛@code@Configuration｝类
 *对于{@code@Profile（{“p1”，“p2”}）}，该类将不会被注册或处理，除非
 *至少已激活配置文件“p1”或“p2”。
 *
 *<p>如果给定的配置文件以NOT运算符（{@code！}）为前缀，则带注释的
 *如果配置文件<em>未</em>处于活动状态，则会注册组件&mdash；例如
 *给定{@code@Profile（{“p1”，“！p2”}）}，如果配置文件“p1”处于活动状态，则将进行注册
 *或者如果配置文件“p2”是<em>而不是</em>活动的。
 *
 *＜p＞如果省略了｛@code@Profile｝注释，则无论何时都将进行注册
 *其中（如果有）配置文件处于活动状态。
 *
 *<p><b>注意：</b>在{@code@Bean}方法上使用{@code@Profile}，可能会出现特殊情况
 *apply:在重载的｛@code@Bean｝方法具有相同Java方法名称的情况下
 *（类似于构造函数重载），｛@code@Profile｝条件需要
 *在所有重载方法上一致声明。如果条件不一致，
 *只有重载方法中第一个声明上的条件才重要。
 *因此，｛@code@Profile｝不能用于选择具有
 *特定论点签名优于另一论点签名；所有工厂方法之间的分辨率
 *对于同一个bean，在创建时遵循Spring的构造函数解析算法。
 *<b>使用不同的Java方法名指向相同的{@link-Bean#name-Bean-name}
 *如果您想定义具有不同配置文件条件的替代bean</b>；
 *请参阅｛@link Configuration@Configuration｝的javadoc中的｛@code ProfileDatabase Config｝。
 *
 *＜p＞当通过XML定义Springbeans时
 *可以使用{@code＜beans＞}元素。请参阅中的文档
 *｛@code spring-beans｝XSD（3.1版或更高版本）以获取详细信息。
 *
 *@作者Chris Beams
 *@作者Phillip Webb
 *@作者Sam Brannen
 *@自3.1起
 *@请参阅可配置环境#setActiveProfiles
 *@请参阅可配置环境#setDefaultProfiles
 *@请参阅抽象环境#ACTIVE_PROFILES_PROPERTY_NAME
 *@请参阅抽象环境#DEFAULT_PROFILES_PROPERTY_NAME
 *@见条件
 *@参见org.springframework.test.context.ActiveProfiles
 */
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional(ProfileCondition.class)
public @interface Profile {

	/**
	 * The set of profiles for which the annotated component should be registered.
	 */
	/**
	 *应为其注册注释组件的配置文件集。
	 */
	String[] value();

}
